/**
* <p>Title: I18nUtil.java<／p>
* <p>Copyright: Copyright © 2010-2014<／p>
* <p>Company: jumei<／p>
* @author cdyf
* @date 2015年1月4日 下午2:08:46
* @version 1.0
*/

package com.mdc.mansion.common.util;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.springframework.context.ApplicationContext;

import com.alibaba.fastjson.JSONObject;
import com.mdc.mansion.common.context.AppContext;


/**
 * <p>com.mdc.mansion.common.util.I18nUtil</p>
 * <p>Title: I18nUtil</p>
 * <p>Copyright: Copyright © 2010-2014</p>
 * <p>Company: jumei</p>
 * @author xiang.liu
 * @version 1.0
 */
public class I18nUtil {
    static Map<String,Locale> languageMap = new HashMap<>();
    static {
        languageMap.put("chinese", Locale.SIMPLIFIED_CHINESE);
        languageMap.put("english", Locale.ENGLISH);
        languageMap.put("indonesia", new Locale("in","ID"));
    }
    
    public static String getMessage(String key) {
        return getMessage(key, new String[0]);
    }
    public static String getMessage(String key, String... params) {
        String content = key;
        JSONObject contentObject = new JSONObject();
        ApplicationContext applicationContext = AppContext.getSpringApplicationContext();
        if(applicationContext!=null){
            for(String language : languageMap.keySet()){
                contentObject.put(language, applicationContext.getMessage(key, params, languageMap.get(language)));
            }
            content = contentObject.toJSONString();
        }
        return content;
    }
}
